package localAI.agents;

import localAI.env.Enviroment;
import localAI.env.def.Direction;
import localAI.env.def.Orientation;
/**
 *
 * @author orcas
 */
public abstract class Agent {

    private String name;
    private int row;
    private int col;
    private Orientation orientation;

    public Agent(String name, int row, int col, Orientation orientation) {
        this.name = name;
        this.row = row;
        this.col = col;
        this.orientation = orientation;
    }

    public abstract Direction getMove(Enviroment env);

    public String getName() {
        return name;
    }

    public int getRow() {
        return row;
    }

    public int getCol() {
        return col;
    }

    public Orientation getOrientation() {
        return this.orientation;
    }

    public int[] getForward() {
        int newCell[] = {row, col};
        switch (this.orientation) {
            case North: {newCell[0]--; break;}
            case East: {newCell[1]++; break;}
            case West: {newCell[1]--; break;}
            case South: {newCell[0]++; break;}
            default: System.out.println("no way.");
        }
        return newCell;
    }

    public void updatePosition(Direction move) {
        if (move.equals(Direction.right)) {
            switch (this.orientation) {
                case North: {this.orientation = orientation.East; break;}
                case East: {this.orientation = orientation.South; break;}
                case West: {this.orientation = orientation.North; break;}
                case South: {this.orientation = orientation.West; break;}
            }
        }
        else if (move.equals(Direction.left)) {
            switch (this.orientation) {
                case North: {this.orientation = orientation.West; break;}
                case East: {this.orientation = orientation.North; break;}
                case West: {this.orientation = orientation.South; break;}
                case South: {this.orientation = orientation.East; break;}
            }
        } 
        //fwd
        else {
            int newCell[] = getForward();
            row = newCell[0];
            col = newCell[1];
        }
    }
}
